﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QStringList>
#include <QFont>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //设置水平头 --》树状列表框的树根
    ui->treeWidget->setHeaderLabel("我的好友");

    //设置顶层节点
    QTreeWidgetItem *item1=new QTreeWidgetItem(QStringList()<<"高中同学");
    ui->treeWidget->addTopLevelItem(item1);

    QTreeWidgetItem *item2=new QTreeWidgetItem(QStringList()<<"大学同学");
    ui->treeWidget->addTopLevelItem(item2);

    QTreeWidgetItem *item3=new QTreeWidgetItem(QStringList()<<"研究生同学");
    ui->treeWidget->addTopLevelItem(item3);

    //在高中同学这个顶层节点的下面继续添加子节点
    QTreeWidgetItem *item11=new QTreeWidgetItem(QStringList()<<"马化腾");
    QTreeWidgetItem *item12=new QTreeWidgetItem(QStringList()<<"王传福");
    QTreeWidgetItem *item13=new QTreeWidgetItem(QStringList()<<"许家印");
    item1->addChild(item11);
    item1->addChild(item12);
    item1->addChild(item13);;


    QTreeWidgetItem *newit = new QTreeWidgetItem(QStringList() << "d");
    QTreeWidgetItem *newit2 = new QTreeWidgetItem(QStringList() << "e");
    item11->addChild(newit);
    item11->addChild(newit2);

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
{

    qDebug() << item->text(column)  << column;
}

